package com.ruiysoft.util;

import java.math.BigDecimal;
import java.util.Optional;

/**
 * Date : 2018/11/3
 *
 * @author WenJialu
 */
public enum CurrencyUtils {

	INSTANCE;

	public BigDecimal cent2Yuan(Long cent){
		if (null == cent) {
			return NumberConst.ZERO_DECIMAL;
		}
		return BigDecimal.valueOf(cent).divide(NumberConst.HUNDRED_DECIMAL, 2, BigDecimal.ROUND_HALF_UP);
	}

	public BigDecimal cent2YuanDecimal(Long cent) {
		return Optional.ofNullable(cent)
				.map(c ->
						new BigDecimal(Long.toString(cent))
								.divide(NumberConst.HUNDRED_DECIMAL, 2, BigDecimal.ROUND_HALF_UP))
				.orElse(BigDecimal.ZERO);
	}

	public Long yuan2Cent(BigDecimal yuan) {
		if (null == yuan) {
			return 0L;
		}
		return NumberConst.HUNDRED_DECIMAL.multiply(yuan).longValue();
	}

}
